package com.vm.action.phoneInfo;

import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Preparable;
import com.vm.action.ActionSuper;
import com.vm.common.Page;
import com.vm.dao.phoneInfo.IPhoneInfoDao;
import com.vm.entity.PhoneInfo;
import com.vm.log4j.CustomizeLog4j;
import com.vm.util.SQLUtils;

public class PhoneInfoAction  extends ActionSuper implements Preparable  {

	private static Logger log = CustomizeLog4j.getLogger(PhoneInfoAction.class);
	//引入手机信息
	private IPhoneInfoDao phoneInfoDao;
	
	
	private PhoneInfo phoneInfo;

	
	private String pageLinkList;
	
	private Page<PhoneInfo> page;
	
	//private String phoneBrand;
	

//	private Map<String,String> brandMap;
//	
//	
//	private Integer brandId;
	
	
	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
//		this.brandMap = this.brandDao.getSelectPoMap("select id as id,brandName as name from Brand");

	}
	/**
	 *  实现的列表化手机信息
	 * @return
	 * @throws Exception
	 */
	public String list() throws Exception {
		String sql = SQLUtils.getPhoneInfoPageSQL(null);
		page = this.phoneInfoDao.page(this.PAGE_ROW_SIZE, super.getPageNumber());
		this.pageLinkList =super.getSplitPageLink("/phone/phoneInfoAction_list.do?", page);
		return SUCCESS;
	}
    /**
     * 添加手机信息
     * @return
     * @throws Exception
     */
	public String add() throws Exception {
		if(this.phoneInfo != null){
			phoneInfo = null;
		}
		return SUCCESS;
	}
	
    /**
     * 保存手机信息方法
     * @return
     * @throws Exception
     */
	public String save() throws Exception {
		String[] msgArg = new String[] { "phoneInfoAction_list.do"};
		String msg = null;
		try {
			phoneInfoDao.save(phoneInfo);
			msg = super.getResourceMessage("insert_phoneInfo_success", msgArg);
		} catch (Exception e) {
			log.error("PhoneInfo save error ", e);
			msg = super.getResourceMessage("insert_phoneInfo_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;


	}
    /**
     * 编辑后返回手机信息方法
     * @return
     * @throws Exception
     */
	public String edit() throws Exception {
		phoneInfo = phoneInfoDao.findById(this.phoneInfo.getPiId());
		return SUCCESS;
	}
    
	public String update() throws Exception {
		String[] msgArg = new String[] { "phoneInfoAction_list.do"};
		String msg = null;
		try {
			phoneInfoDao.update(phoneInfo);
			msg = super.getResourceMessage("update_phoneInfo_success", msgArg);
		} catch (Exception e) {
			log.error("UpdateCircleAction update section error  ", e);
			msg = super.getResourceMessage("update_phoneInfo_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;

	}
   	public String delete() throws Exception {
   		String[] msgArg = new String[] { "phoneInfoAction_list.do"};
		String msg = null;
		try {
			phoneInfoDao.deleteById(this.phoneInfo.getPiId());
			phoneInfo = null;
			msg = super.getResourceMessage("delete_phoneInfo_success", msgArg);
		} catch (Exception e) {
			log.error("delete phoneInfo  error !", e);
			msg = super.getResourceMessage("delete_phoneInfo_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;

	}
   	public String getPageLinkList() {
		return pageLinkList;
	}
	public void setPageLinkList(String pageLinkList) {
		this.pageLinkList = pageLinkList;
	}
	
	public Page<PhoneInfo> getPage() {
		return page;
	}
	public void setPage(Page<PhoneInfo> page) {
		this.page = page;
	}
	
	public IPhoneInfoDao getPhoneInfoDao() {
		return phoneInfoDao;
	}
	public void setPhoneInfoDao(IPhoneInfoDao phoneInfoDao) {
		this.phoneInfoDao = phoneInfoDao;
	}
	public PhoneInfo getPhoneInfo() {
		return phoneInfo;
	}
	public void setPhoneInfo(PhoneInfo phoneInfo) {
		this.phoneInfo = phoneInfo;
	}
	
//	public Map<String, String> getBrandMap() {
//		return brandMap;
//	}
//	public void setBrandMap(Map<String, String> brandMap) {
//		this.brandMap = brandMap;
//	}
	
//	public String getPhoneBrand() {
//		return phoneBrand;
//	}
//	public void setPhoneBrand(String phoneBrand) {
//		this.phoneBrand = phoneBrand;
//	}
	
//	public Integer getBrandId() {
//		return brandId;
//	}
//	public void setBrandId(Integer brandId) {
//		this.brandId = brandId;
//	}
	

	
}
